import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'font-awesome/css/font-awesome.css'
import 'swiper/dist/css/swiper.min.css'
import YDUI from 'vue-ydui'
import 'vue-ydui/dist/ydui.rem.css'

Vue.use(YDUI)
import Vant from 'vant'
import 'vant/lib/index.css'

Vue.use(Vant)
import './common/global'
import './common/preventReClick'
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'

Vue.use(VideoPlayer)

/* 全局过滤器*/
import * as filters from './filters'

Object.keys(filters).forEach(key => {
	Vue.filter(key, filters[key])
})

import './common/clamp'

/* 移动端打印插件*/
import Vconsole from 'vconsole'
//const vConsole = new Vconsole()

/* 将axios绑定到vue原型属性上*/
import request from './common/axios'
Vue.prototype.$axios = request

import Bus from '@/utils/bus.js'

Bus(Vue)

Vue.config.productionTip = false

import aes from './common/aes'

Vue.prototype.$AES = aes

Date.prototype.Format = function (fmt) {
	var o = {
		'M+': this.getMonth() + 1, // 月份
		'd+': this.getDate(), // 日
		'h+': this.getHours(), // 小时
		'm+': this.getMinutes(), // 分
		's+': this.getSeconds(), // 秒
		'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
		'S': this.getMilliseconds() // 毫秒
	}
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
	for (var k in o) {
		if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
	}
	return fmt
}

import JSEncrypt from 'jsencrypt'

Vue.prototype.$getRsaCode = (str) => { // 注册方法
	const pubKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvCkyEkJSy7QWRPZzceERKiMEtdPfCvJbEJj93IqE4nX4CAwuNESEx5jVTBG7TfvOCbUTdcRh9MHPQ0XldVPs/HO8v95OMUXh1+bDrDBPPh3tSgh+2YZB/WxJAY6V6kNPXXnsZBHCpQqTt0INbPrjTGcVNKFphDSmuom3/TxHd5c0dH33xGSL8U0/KXTWto3QmhdAOqCErhMdn6MMNjyaU5qnHq9x0B5shEHSyp3hkBRCcnScnCRRVqTNbeJ2iiyfX6Dd8RqVA9emlj9jHetU+ot7DwwhdMDS2vT6xb32HHEYemN85bPXpjkawuHznKks0dmc5ceHxAalNpmneIVvMwIDAQAB' // ES6 模板字符串 引用 rsa 公钥
	const encryptStr = new JSEncrypt()
	encryptStr.setPublicKey(pubKey) // 设置 加密公钥
	const data = encryptStr.encrypt(str.toString()) // 进行加密
	return data
} // .vue文件中用this.$getRsaCode(this.loginForm.password)调用
if (/android/i.test(navigator.userAgent)) {
	localStorage.setItem('sys', 'Android')
} else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
	localStorage.setItem('sys', 'IOS')
}
localStorage.setItem('isToLogin', 0)

router.beforeEach((to, from, next) => {
	if (!(from.name === 'ExamRoom' && to.name === 'ExamDetail')) {
		if (store.state['axiosPromiseCancel'].length > 0) {
			store.state['axiosPromiseCancel'].forEach(e => {
				if (e && e.f) {
					e.f()
				}
			})
		}
		store.state['axiosPromiseCancel'] = []
	}
	next()
})

window.$Vue = new Vue({
	router,
	store,
	render: h => h(App)
}).$mount('#app')
